
__vars_ = {}
__funcs = {}
__boxes = {}

def add_var(var_name, var_value):
    if __vars_.has_key(var_name):
        raise TypeError("double variable declaration "+var_name)
    __vars_[var_name]=var_value

def get_var( var_name):
    if not __vars_.has_key(var_name):
        raise TypeError("invalid var "+var_name)
    return __vars_[var_name]

def add_func( func_name, func_declaration):
    if __funcs.has_key(func_name):
        raise TypeError("double function declaration "+func_name)
    __funcs[func_name]=func_declaration

def get_func( func_name):
    if not __funcs.has_key(func_name):
        raise TypeError("invalid func "+func_name)
    return __funcs[func_name]

def add_box( box_name, box_instance):
    if __boxes.has_key(box_name):
        raise TypeError("double box declaraion "+box_name)
    __boxes[box_name]=box_instance

def get_box( box_name):
    if not __boxes.has_key(box_name):
        raise TypeError("invalid box "+box_name)
    return __boxes[box_name]


def doesVarExists(var_name):
    return __vars_.has_key(var_name)

def doesBoxExists(box_name):
    return __boxes.has_key(box_name)

def doesFuncExists(func_name):
    return __funcs.has_key(func_name)

def runFunction(func_name, in_vars):
    """runs the function, returning only the first return value"""
    if not __funcs.has_key(func_name):
        raise TypeError("invalid func "+func_name)
    f = get_func(func_name)
    return f[0](in_vars)

def getSingleFunction(func_name):
    if not __funcs.has_key(func_name):
        raise TypeError("invalid func "+func_name)
    f = get_func(func_name)
    return f[0]

def getSingleFunctionDict():
    f = {}
    for func_name in __funcs:
        f[func_name] = getSingleFunction(func_name)
    return f

def getScope():
    return (__boxes, getSingleFunctionDict(), __vars_)
